package cn.tedu.eb_film.utils;


import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * response工具类
 *
 * @author ライナー・ロンテ
 * @since 2023/3/9 10:03
 */
public class ResponseUtils {
    private ServiceCode code;

    public static void sendResponse(HttpServletResponse response,ServiceCode  serviceCode, String message)
            throws IOException {
        response.setContentType("application/json; charset=utf-8");
        PrintWriter writer = response.getWriter();
        JsonResult<Void> jsonResult = new JsonResult<>();
        jsonResult.setState(serviceCode.getValue());
        jsonResult.setMessage(message);
        final String json = JSON.toJSONString(jsonResult);
        writer.println(json);
        writer.close();
    }
}
